#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    struct stat sb;
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    if (stat(argv[1], &sb) == -1) {
        perror("stat");
        exit(EXIT_FAILURE);
    }
    printf("文件类型:                ");
    switch (sb.st_mode & S_IFMT) {
        case S_IFBLK:   printf("block device\n");
            break;
    case S_IFCHR:   printf("character device\n");
            break;
    case S_IFDIR:   printf("directory\n");
            break;
    case S_IFIFO:   printf("FIFO/pipe\n");
            break;
    case S_IFLNK:   printf("symlink\n");
            break;
    case S_IFREG:   printf("regular file\n");
            break;
    case S_IFSOCK:  printf("socket\n");
            break;
    default:        printf("unknown?\n");
            break;
    }
    printf("大小:       %lld bytes\n",(long long) sb.st_size);
    printf("块:         %lld\n",(long long) sb.st_blocks);
    printf("Inode:      %ld\n", (long) sb.st_ino);
    printf("硬链接:     %ld\n", (long) sb.st_nlink);
    printf("权限:       UID=%ld   GID=%ld\n",(long) sb.st_uid, (long) sb.st_gid);
    printf("最近访问:   %s", ctime(&sb.st_atime));
    printf("最近更改:   %s", ctime(&sb.st_ctime));
    printf("最近改动:   %s", ctime(&sb.st_mtime));
    exit(EXIT_SUCCESS);
}